﻿@model Models.Models.UserPermissions
@using WebApp.Classes;

@using (Ajax.BeginForm("EditUser", "Account", null, new AjaxOptions(), new { @id = "formUser", @class = "form-horizontal" }))
{                
            <fieldset style="height: 440px; border-style: ridge; border-width: 1px; border-color: #DDDDDD;" id="divUser">

            @Html.ValidationSummary()

            @Html.HiddenFor(model => model.User.UserID)    
            @Html.HiddenFor(m => m.User.StoreID)

            <div class="control-group">    
                <label class="control-label" for="input01">@Html.LabelFor(m => m.User.FirstName)</label>
                <div class="controls">@Html.TextBoxFor(m => m.User.FirstName, new { @class = "input-medium" })</div>
            </div>

            <div class="control-group">    
                <label class="control-label" for="input01">@Html.LabelFor(m => m.User.LastName)</label>
                <div class="controls">@Html.TextBoxFor(m => m.User.LastName, new { @class = "input-medium" })</div>
            </div>

            <div class="control-group">    
                <label class="control-label" for="input01">@Html.LabelFor(m => m.User.UserEmail)</label>
                <div class="controls">@Html.TextBoxFor(m => m.User.UserEmail, new { @class = "input-medium" })</div>
            </div>

            <div class="control-group">    
                <label class="control-label" for="input01">@Html.LabelFor(m => m.User.EmailAlertRecipient)</label>
                <div class="controls">@Html.CheckBoxFor(m => m.User.EmailAlertRecipient)</div>
            </div>

            <div class="control-group">    
                <label class="control-label" for="input01">@Html.LabelFor(m => m.User.BillingReportRecipient)</label>
                <div class="controls">@Html.CheckBoxFor(m => m.User.BillingReportRecipient)</div>
            </div>

            <div style="overflow: auto; height: 170px;"> 
            <table class="table">
            @if (Model.Menu != null)
            {
                foreach (var menu in Model.Menu)
                {
                    var name = menu.Name.Substring(menu.Name.LastIndexOf("|$") + 2).Trim();
                    
                    <tr>
                        <td>
                            @Html.Label("", name)
                        </td>
                        <td>
                            @Html.GetLookUp(menu.ID.ToString(), menu.UserRights, "MenuStatus")
                        </td>
                    </tr>
                }
            }
            </table>
            </div>

        </fieldset>            
        <br />
    
            {
                var rights = new WebApp.Classes.UserRights("User Management");

                if (rights.FullControl || rights.Editable)
                { 
                <div class="">
                    @if (!Model.User.RevokeStatus)
                    {
                        if (Model.User.UserID == 0)
                        {
                            <button type="submit" class="btn btn-inverse" id="createUser"><i class="icon-ok icon-white"></i> Create</button>            
                        }
                        else
                        { 
                            <button type="submit" class="btn btn-inverse" id="updateUser"><i class="icon-ok icon-white"></i> Update</button>                                        
                            @Ajax.ImageActionLink("<i class=\"icon-refresh icon-white\"></i> Reset Password", "ResetPassword", "Account", new { @userID = Model.User.UserID }, new AjaxOptions() { HttpMethod = "POST" }, new { @class = "btn btn-inverse" })
                        }
                    }
                    @if (Model.User.UserID != 0)
                    {
                        if (Model.User.RevokeStatus)
                        {
                            <button type="button" class="btn btn-inverse" id="activate"><i class="icon-repeat icon-white"></i> Activate</button>
                        }
                        else
                        {                            
                            <button type="button" class="btn btn-inverse" id="revoke"><i class="icon-remove icon-white"></i> Revoke</button>
                        }
                    }
                </div>
                }
            }
}